<template>
  <div class="user-info">
    <div class="all_main">
      <dragdrop :width="0" :widthLeft="'130px'">
        <template slot="left">
          <div class="all_left">
            <div class="grid-content bg-purple">
              <div class="header_title">
                <span>部门列表</span>
              </div>
              <div class="department_tree">
                <el-tree
                  :data="deptTree"
                  :props="defaultProps"
                  @node-click="handleNodeClick"
                  :expand-on-click-node="false"
                  :highlight-current="true"
                  :indent="1"
                   node-key="pkDepartmentId"
                  :default-expanded-keys="idArr"
                ></el-tree>
              </div>
            </div>
          </div>
        </template>
        <template slot="right">
          <div class="all_right">
            <div class="grid-content bg-purple">
              <div class="header_title">
                <span>人员列表</span>
              </div>
              <el-form :inline="true" :model="elform" size="mini" ref="elform" class="form">
                <el-form-item label="姓名:">
                  <el-input
                    placeholder="用户姓名"
                    v-model="userName"
                    clearable
                    size="mini"
                    style="width: 100px"
                  ></el-input>
                </el-form-item>
                <el-form-item label="编号:">
                  <el-input
                    placeholder="用户编号"
                    v-model="userNumber"
                    clearable
                    size="mini"
                    style="width: 120px"
                  ></el-input>
                </el-form-item>
                <el-form-item label="卡号:">
                  <el-input
                    placeholder="卡号"
                    v-model="cardNumber"
                    clearable
                    size="mini"
                    style="width: 120px"
                  ></el-input>
                </el-form-item>
                <el-form-item>
                  <!-- <div> -->
                  <el-button type="primary" @click="gotosearch()" size="mini">查询</el-button>
                  <el-button type="primary" @click="resetfilter()" size="mini">重置条件</el-button>
                  <!-- </div>
                  <div>-->
                  <template v-if="isauth('user_edit')">
                    <el-button type="primary" @click="handleAddclick" size="mini">新增人员</el-button>
                    <el-button type="primary" @click="showImportDialog" size="mini">导入</el-button>
                    <el-button type="primary" @click="exportexeclto()" size="mini">导出</el-button>
                    <el-button
                      type="primary"
                      @click="exportexeclto('print')"
                      size="mini"
                      style="margin-right: 10px"
                    >打印</el-button>
                  </template>
                </el-form-item>
                <el-form-item>
                  <el-popover placement="top" width="500" trigger="click">
                    <div>
                      <el-row>
                        <el-checkbox
                          style="width: 10%"
                          :label="formThead.userName.label"
                          v-model="formThead.userName.checked"
                          @change="checkboxChanged()"
                          margin-right:10px
                        ></el-checkbox>
                        <el-checkbox
                          style="width: 10%"
                          :label="formThead.userNumber.label"
                          v-model="formThead.userNumber.checked"
                          @change="checkboxChanged()"
                        ></el-checkbox>
                        <el-checkbox
                          style="width: 10%"
                          :label="formThead.cardNumber.label"
                          v-model="formThead.cardNumber.checked"
                          @change="checkboxChanged()"
                        ></el-checkbox>
                        <el-checkbox
                          style="width: 10%"
                          :label="formThead.userSexStr.label"
                          v-model="formThead.userSexStr.checked"
                          @change="checkboxChanged()"
                        ></el-checkbox>
                      </el-row>
                      <el-row>
                        <el-checkbox
                          style="width: 10%"
                          :label="formThead.departmentName.label"
                          v-model="formThead.departmentName.checked"
                          @change="checkboxChanged()"
                        ></el-checkbox>
                        <el-checkbox
                          style="width: 10%"
                          :label="formThead.groupName.label"
                          v-model="formThead.groupName.checked"
                          @change="checkboxChanged()"
                        ></el-checkbox>
                        <el-checkbox
                          style="width: 10%"
                          :label="formThead.roomName.label"
                          v-model="formThead.roomName.checked"
                          @change="checkboxChanged()"
                        ></el-checkbox>
                        <el-checkbox
                          style="width: 10%"
                          :label="formThead.idCard.label"
                          v-model="formThead.idCard.checked"
                          @change="checkboxChanged()"
                        ></el-checkbox>
                      </el-row>
                      <el-row>
                        <el-checkbox
                          style="width: 10%"
                          :label="formThead.birthday.label"
                          v-model="formThead.birthday.checked"
                          @change="checkboxChanged()"
                        ></el-checkbox>
                        <el-checkbox
                          style="width: 10%"
                          :label="formThead.phoneNumber.label"
                          v-model="formThead.phoneNumber.checked"
                          @change="checkboxChanged()"
                        ></el-checkbox>
                        <el-checkbox
                          style="width: 10%"
                          :label="formThead.contact.label"
                          v-model="formThead.contact.checked"
                          @change="checkboxChanged()"
                        ></el-checkbox>
                        <el-checkbox
                          style="width: 10%"
                          :label="formThead.contactPhone.label"
                          v-model="formThead.contactPhone.checked"
                          @change="checkboxChanged()"
                        ></el-checkbox>
                      </el-row>
                      <el-row>
                        <el-checkbox
                          style="width: 10%"
                          :label="formThead.homeAddress.label"
                          v-model="formThead.homeAddress.checked"
                          @change="checkboxChanged()"
                        ></el-checkbox>
                        <el-checkbox
                          style="width: 10%"
                          :label="formThead.postCode.label"
                          v-model="formThead.postCode.checked"
                          @change="checkboxChanged()"
                        ></el-checkbox>
                        <el-checkbox
                          style="width: 10%"
                          :label="formThead.email.label"
                          v-model="formThead.email.checked"
                          @change="checkboxChanged()"
                        ></el-checkbox>
                        <el-checkbox
                          style="width: 10%"
                          :label="formThead.regTime.label"
                          v-model="formThead.regTime.checked"
                          @change="checkboxChanged()"
                        ></el-checkbox>
                      </el-row>
                      <el-row>
                        <el-checkbox
                          style="width: 10%"
                          :label="formThead.limitPassword.label"
                          v-model="formThead.limitPassword.checked"
                          @change="checkboxChanged()"
                        ></el-checkbox>
                        <el-checkbox
                          style="width: 10%"
                          :label="formThead.advanceBalance.label"
                          v-model="formThead.advanceBalance.checked"
                          @change="checkboxChanged()"
                        ></el-checkbox>
                        <!-- <el-checkbox
                          style="width: 10%"
                          :label="formThead.platformBalance.label"
                          v-model="formThead.platformBalance.checked"
                          @change="checkboxChanged()"
                        ></el-checkbox> -->
                        <!-- <el-checkbox
                          style="width: 10%"
                          :label="formThead.cardBalance.label"
                          v-model="formThead.cardBalance.checked"
                          @change="checkboxChanged()"
                        ></el-checkbox>-->
                      </el-row>
                    </div>
                    <el-button type="primary" slot="reference" size="mini">自定义显示列</el-button>
                  </el-popover>
                </el-form-item>
              </el-form>
              <el-table
                :data="tableData"
                border
                row-key="id"
                :header-cell-style="headFirst"
                ref="tableData"
                v-loading="loading"
                :cell-style="(res) => headFirst_col(res, [])"
              >
                <el-table-column
                  :label="formThead.userName.label"
                  :prop="formThead.userName.prop"
                  v-if="formThead.userName.checked"
                ></el-table-column>
                <el-table-column
                  :label="formThead.userNumber.label"
                  :prop="formThead.userNumber.prop"
                  v-if="formThead.userNumber.checked"
                  min-width="100px"
                ></el-table-column>
                <el-table-column
                  :label="formThead.cardNumber.label"
                  :prop="formThead.cardNumber.prop"
                  v-if="formThead.cardNumber.checked"
                  min-width="100px"
                ></el-table-column>
                <el-table-column
                  :label="formThead.departmentName.label"
                  :prop="formThead.departmentName.prop"
                  v-if="formThead.departmentName.checked"
                  min-width="100px"
                ></el-table-column>
                <el-table-column
                  :label="formThead.groupName.label"
                  :prop="formThead.groupName.prop"
                  v-if="formThead.groupName.checked"
                ></el-table-column>
                <el-table-column
                  :label="formThead.roomName.label"
                  :prop="formThead.roomName.prop"
                  v-if="formThead.roomName.checked"
                ></el-table-column>
                <el-table-column
                  :label="formThead.userSexStr.label"
                  :prop="formThead.userSexStr.prop"
                  v-if="formThead.userSexStr.checked"
                ></el-table-column>
                <el-table-column
                  :label="formThead.birthday.label"
                  :prop="formThead.birthday.prop"
                  v-if="formThead.birthday.checked"
                  min-width="94px"
                ></el-table-column>
                <el-table-column
                  :label="formThead.idCard.label"
                  :prop="formThead.idCard.prop"
                  v-if="formThead.idCard.checked"
                  min-width="160px"
                ></el-table-column>
                <el-table-column
                  :label="formThead.loginName.label"
                  :prop="formThead.loginName.prop"
                  v-if="formThead.loginName.checked"
                  min-width="110px"
                ></el-table-column>
                <el-table-column
                  :label="formThead.phoneNumber.label"
                  :prop="formThead.phoneNumber.prop"
                  v-if="formThead.phoneNumber.checked"
                  min-width="100px"
                ></el-table-column>
                <el-table-column
                  :label="formThead.contact.label"
                  :prop="formThead.contact.prop"
                  v-if="formThead.contact.checked"
                ></el-table-column>
                <el-table-column
                  :label="formThead.contactPhone.label"
                  :prop="formThead.contactPhone.prop"
                  v-if="formThead.contactPhone.checked"
                ></el-table-column>
                <el-table-column
                  :label="formThead.homeAddress.label"
                  :prop="formThead.homeAddress.prop"
                  v-if="formThead.homeAddress.checked"
                ></el-table-column>
                <el-table-column
                  :label="formThead.postCode.label"
                  :prop="formThead.postCode.prop"
                  v-if="formThead.postCode.checked"
                ></el-table-column>
                <el-table-column
                  :label="formThead.email.label"
                  :prop="formThead.email.prop"
                  v-if="formThead.email.checked"
                ></el-table-column>
                <el-table-column
                  :label="formThead.regTime.label"
                  :prop="formThead.regTime.prop"
                  v-if="formThead.regTime.checked"
                  min-width="144px"
                ></el-table-column>
                <el-table-column
                  :label="formThead.limitPassword.label"
                  :prop="formThead.limitPassword.prop"
                  v-if="formThead.limitPassword.checked"
                ></el-table-column>

                <!-- <el-table-column
                  :label="formThead.platformBalance.label"
                  :prop="formThead.platformBalance.prop"
                  v-if="formThead.platformBalance.checked"
                >
                  <template slot-scope="scope">
                    {{
                    scope.row.platformBalance | amountyuan
                    }}
                  </template>
                </el-table-column> -->

                <el-table-column
                  :label="formThead.advanceBalance.label"
                  :prop="formThead.advanceBalance.prop"
                  v-if="formThead.advanceBalance.checked"
                  min-width="100px"
                >
                  <template slot-scope="scope">
                    {{
                    scope.row.advanceBalance | amountyuan
                    }}
                  </template>
                </el-table-column>
                <!-- <el-table-column
                  :label="formThead.cardBalance.label"
                  :prop="formThead.cardBalance.prop"
                  v-if="formThead.cardBalance.checked"
                >
                  <template slot-scope="scope">
                    {{
                    scope.row.cardBalance | amountyuan
                    }}
                  </template>
                </el-table-column>-->
                <el-table-column width="200px" label="操作" aling="center" v-if="isauth('user_edit')">
                  <template slot-scope="scope">
                    <el-button type="text" size="mini" @click="toH5User(scope.row)">H5详情</el-button>
                    <el-button type="text" size="mini" @click="addOrUpdateHandle(scope.row)">修改</el-button>
                    <el-button type="text" size="mini" @click="resetPassword(scope.row)">重置密码</el-button>
                    <el-button
                      type="text"
                      size="mini"
                      style="color: red"
                      @click="removeUser(scope.row)"
                    >删除</el-button>
                  </template>
                </el-table-column>
              </el-table>
              <!-- 新增学生弹窗 -->
              <el-dialog
                title="添加用户信息"
                :visible.sync="addDialogFormVisible"
                width="800px"
                center
                :close-on-click-modal="false"
                :before-close="closeDialogAdd"
              >
                <div class="unit_parameter">
                  <el-form
                    :model="addformdata"
                    :rules="addformdatamyrules"
                    ref="addformdata"
                    id="dialogup"
                  >
                    <el-row>
                      <el-col :span="11">
                        <!-- <el-form-item label="登录名" label-width="80px" prop="loginName">
                        <el-input
                          v-model="addformdata.loginName"
                          autocomplete="off"
                          style="width:90%"
                        ></el-input>
                        </el-form-item>-->
                        <el-form-item label="用户姓名" label-width="88px" prop="userName">
                          <el-input
                            v-model="addformdata.userName"
                            autocomplete="off"
                            style="width: 90%"
                          ></el-input>
                        </el-form-item>
                      </el-col>
                      <el-col :span="11">
                        <!-- <el-form-item label="用户卡号" label-width="88px" prop="cardNumber">
                        <el-input
                          v-model.number="addformdata.cardNumber"
                          οninput="value=value.replace(/[^\d]/g,'')"
                          maxlength="10"
                          autocomplete="off"
                          style="width:90%"
                        ></el-input>
                        </el-form-item>-->
                        <el-form-item label="用户编号" label-width="88px" prop="userNumber">
                          <el-input
                            v-model="addformdata.userNumber"
                            autocomplete="off"
                            style="width: 90%"
                          ></el-input>
                        </el-form-item>
                      </el-col>
                    </el-row>
                    <el-row>
                      <el-col :span="23">
                        <el-form-item label="部门" label-width="88px" prop="departmentGuid">
                          <el-cascader
                            v-model="addformdata.departmentGuid"
                            :options="deptTree"
                            ref="cascaderAddDept"
                            placeholder="请选择部门"
                            @change="handleChangeDept"
                            style="width: 90%"
                          ></el-cascader>
                        </el-form-item>
                      </el-col>
                    </el-row>
                    <el-row>
                      <el-col :span="11">
                        <el-form-item label="身份/分组" label-width="88px" prop="groupGuid">
                          <el-select
                            v-model="addformdata.groupGuid"
                            placeholder="请选择分组"
                            style="width: 90%"
                          >
                            <el-option
                              v-for="item in groupList"
                              :key="item.groupGuid"
                              :label="item.groupName"
                              :value="item.groupGuid"
                            ></el-option>
                          </el-select>
                        </el-form-item>
                      </el-col>
                      <el-col :span="11">
                        <el-form-item label="身份证" label-width="88px" prop="idCard">
                          <el-input
                            v-model="addformdata.idCard"
                            autocomplete="off"
                            style="width: 90%"
                          ></el-input>
                        </el-form-item>
                      </el-col>
                      <el-col :span="11">
                        <el-form-item label="性别" label-width="88px" prop="userSex">
                          <el-radio-group v-model="addformdata.userSex">
                            <el-radio label="0">男</el-radio>
                            <el-radio label="1">女</el-radio>
                          </el-radio-group>
                        </el-form-item>
                      </el-col>
                      <!-- <el-col :span="11">
                        <el-form-item label="生日" label-width="88px" prop="birthday">
                          <el-date-picker
                            v-model="addformdata.birthday"
                            type="date"
                            value-format="yyyy-MM-dd"
                            placeholder="选择日期时间"
                            style="width: 90%"
                          ></el-date-picker>
                        </el-form-item>
                      </el-col>-->
                      <el-col :span="11">
                        <el-form-item label="手机号" label-width="88px" prop="phoneNumber">
                          <el-input
                            v-model.number="addformdata.phoneNumber"
                            autocomplete="off"
                            style="width: 90%"
                          ></el-input>
                        </el-form-item>
                      </el-col>
                      <el-col :span="11">
                        <el-form-item label="超额密码" label-width="88px" prop="limitPassword">
                          <el-input
                            v-model="addformdata.limitPassword"
                            οninput="value=value.replace(/[^\d]/g,'')"
                            maxlength="4"
                            autocomplete="off"
                            style="width: 90%"
                          ></el-input>
                        </el-form-item>
                      </el-col>

                      <el-col :span="11">
                        <el-form-item label="住宿类型" label-width="88px" prop="userType">
                          <el-radio-group v-model="addformdata.userType">
                            <el-radio :label="0">住校生</el-radio>
                            <el-radio :label="2">走读生</el-radio>
                          </el-radio-group>
                        </el-form-item>
                      </el-col>
                    </el-row>
                    <el-row v-if="addformdata.userType == 0">
                      <el-col :span="9">
                        <!-- <el-form-item label="入住房间" label-width="88px" prop="roomGuid">
                          <el-cascader
                            v-model="addformdata.roomGuid"
                            :options="dataTree"
                            ref="cascaderAddRoom"
                            placeholder="请选择入住房间"
                            @change="handleChangeRoom"
                            style="width: 90%"
                            clearable
                          ></el-cascader>
                        </el-form-item>-->
                        <el-form-item label="楼栋" label-width="88px">
                          <el-select
                            v-model="addformdata.buildingGuid"
                            placeholder="请选择楼栋"
                            clearable
                            style="width: 160px"
                            @change="selectLay"
                          >
                            <el-option
                              v-for="item in buildingInfoList"
                              :key="item.buildingGuid"
                              :label="item.buildingName"
                              :value="item.buildingGuid"
                            ></el-option>
                          </el-select>
                        </el-form-item>
                      </el-col>
                      <el-col :span="5">
                        <el-form-item label="楼层">
                          <el-select
                            v-model="addformdata.layers"
                            placeholder="请选择"
                            clearable
                            @change="selectRoom"
                            style="width: 100px"
                          >
                            <el-option
                              v-for="item in layersList"
                              :key="item.value"
                              :label="item.label"
                              :value="item.value"
                            ></el-option>
                          </el-select>
                        </el-form-item>
                      </el-col>
                      <el-col :span="9">
                        <el-form-item label="房间">
                          <el-select
                            v-model="addformdata.roomGuid"
                            placeholder="请选择房间"
                            clearable
                            style="width: 160px"
                          >
                            <el-option
                              v-for="item in roomList"
                              :key="item.roomGuid"
                              :label="item.roomName"
                              :value="item.roomGuid"
                            ></el-option>
                          </el-select>
                        </el-form-item>
                      </el-col>
                    </el-row>
                    <el-row>
                      <el-col :span="11">
                        <el-form-item label="联系人" label-width="88px" prop="contact">
                          <el-input
                            v-model="addformdata.contact"
                            autocomplete="off"
                            style="width: 90%"
                          ></el-input>
                        </el-form-item>
                      </el-col>
                      <el-col :span="11">
                        <el-form-item label="联系电话" label-width="88px" prop="contactPhone">
                          <el-input
                            v-model.number="addformdata.contactPhone"
                            autocomplete="off"
                            style="width: 90%"
                          ></el-input>
                        </el-form-item>
                      </el-col>
                      <el-col :span="11">
                        <el-form-item label="家庭住址" label-width="88px" prop="homeAddress">
                          <el-input
                            v-model="addformdata.homeAddress"
                            autocomplete="off"
                            style="width: 90%"
                          ></el-input>
                        </el-form-item>
                      </el-col>
                      <el-col :span="11">
                        <el-form-item label="电子邮箱" label-width="88px" prop="email">
                          <el-input
                            v-model="addformdata.email"
                            autocomplete="off"
                            style="width: 90%"
                          ></el-input>
                        </el-form-item>
                      </el-col>

                      <el-col :span="11">
                        <el-form-item label="邮政编码" label-width="88px" prop="postCode">
                          <el-input
                            v-model="addformdata.postCode"
                            autocomplete="off"
                            style="width: 90%"
                          ></el-input>
                        </el-form-item>
                      </el-col>
                    </el-row>
                  </el-form>
                </div>
                <div slot="footer" class="dialog-footer">
                  <el-button @click="addvisible">取 消</el-button>
                  <el-button type="primary" @click="confirmAdd('addForm')">确 定</el-button>
                </div>
              </el-dialog>
              <!-- 编辑学生 -->
              <el-dialog
                title="编辑用户信息"
                :visible.sync="editDialogFormVisible"
                width="800px"
                center
                :close-on-click-modal="false"
                :before-close="closeDialogEdit"
              >
                <div class="unit_parameter">
                  <el-form
                    :model="editformdata"
                    :rules="editformdatamyrules"
                    ref="editformdata"
                    id="dialogup"
                  >
                    <el-row>
                      <el-col :span="11">
                        <el-form-item label="用户卡号" label-width="88px" prop="cardNumber">
                          <el-input
                            v-model="editformdata.cardNumber"
                            οninput="value=value.replace(/[^\d]/g,'')"
                            maxlength="10"
                            autocomplete="off"
                            style="width: 90%"
                            disabled
                          ></el-input>
                        </el-form-item>
                      </el-col>
                      <el-col :span="11">
                        <el-form-item label="登录名" label-width="88px" prop="loginName">
                          <el-input
                            v-model="editformdata.loginName"
                            autocomplete="off"
                            style="width: 90%"
                            :disabled="true"
                          ></el-input>
                        </el-form-item>
                      </el-col>
                      <el-col :span="11">
                        <el-form-item label="用户姓名" label-width="88px" prop="userName">
                          <el-input v-model="editformdata.userName" style="width: 90%"></el-input>
                        </el-form-item>
                      </el-col>
                      <el-col :span="11">
                        <el-form-item label="用户编号" label-width="88px" prop="userNumber">
                          <el-input
                            v-model="editformdata.userNumber"
                            autocomplete="off"
                            style="width: 90%"
                          ></el-input>
                        </el-form-item>
                      </el-col>
                      <el-col :span="23">
                        <el-form-item label="部门" label-width="88px" prop="departmentGuid">
                          <el-cascader
                            v-model="editformdata.departmentGuid"
                            :options="deptTree"
                            ref="cascaderEditDept"
                            placeholder="请选择部门"
                            @change="handleChangeDept"
                            style="width: 90%"
                          ></el-cascader>
                        </el-form-item>
                      </el-col>
                      <el-col :span="11">
                        <el-form-item label="身份/分组" label-width="88px" prop="groupGuid">
                          <el-select
                            v-model="editformdata.groupGuid"
                            placeholder="请选择身份/分组"
                            style="width: 90%"
                          >
                            <el-option
                              v-for="item in groupList"
                              :key="item.groupGuid"
                              :label="item.groupName"
                              :value="item.groupGuid"
                            ></el-option>
                          </el-select>
                        </el-form-item>
                      </el-col>

                      <el-col :span="11">
                        <el-form-item label="超额密码" label-width="88px" prop="limitPassword">
                          <el-input
                            v-model="editformdata.limitPassword"
                            οninput="value=value.replace(/[^\d]/g,'')"
                            maxlength="4"
                            autocomplete="off"
                            style="width: 90%"
                          ></el-input>
                        </el-form-item>
                      </el-col>
                      <el-col :span="11">
                        <el-form-item label="住宿类型" label-width="88px" prop="userType">
                          <el-radio-group v-model="editformdata.userType">
                            <el-radio :label="0">住校生</el-radio>
                            <el-radio :label="2">走读生</el-radio>
                          </el-radio-group>
                        </el-form-item>
                      </el-col>
                      <el-col :span="11">
                        <el-form-item label="性别" label-width="88px" prop="userSex">
                          <el-radio-group v-model="editformdata.userSex">
                            <el-radio :label="0">男</el-radio>
                            <el-radio :label="1">女</el-radio>
                          </el-radio-group>
                        </el-form-item>
                      </el-col>
                    </el-row>

                    <!-- <el-col :span="23">
                        <el-form-item label="入住房间" label-width="88px" prop="roomGuid">
                          <el-cascader
                            v-model="editformdata.roomGuid"
                            :options="dataTree"
                            ref="cascaderEditRoom"
                            placeholder="请选择入住房间"
                            @change="handleChangeRoom"
                            style="width: 90%"
                            clearable
                          ></el-cascader>
                        </el-form-item>
                    </el-col>-->
                    <el-row v-if="editformdata.userType == 0">
                      <el-col :span="9">
                        <el-form-item label="楼栋" label-width="88px">
                          <el-select
                            v-model="editformdata.buildingGuid"
                            placeholder="请选择楼栋"
                            size="mini"
                            clearable
                            style="width: 160px"
                            @change="selectLay"
                          >
                            <el-option
                              v-for="item in buildingInfoList"
                              :key="item.buildingGuid"
                              :label="item.buildingName"
                              :value="item.buildingGuid"
                            ></el-option>
                          </el-select>
                        </el-form-item>
                      </el-col>
                      <el-col :span="5">
                        <el-form-item label="楼层">
                          <el-select
                            v-model="editformdata.layers"
                            placeholder="请选择"
                            size="mini"
                            clearable
                            @change="selectRoom"
                            style="width: 100px"
                          >
                            <el-option
                              v-for="item in layersList"
                              :key="item.value"
                              :label="item.label"
                              :value="item.value"
                            ></el-option>
                          </el-select>
                        </el-form-item>
                      </el-col>
                      <el-col :span="9">
                        <el-form-item label="房间">
                          <el-select
                            v-model="editformdata.roomGuid"
                            placeholder="请选择房间"
                            size="mini"
                            clearable
                            style="width: 160px"
                          >
                            <el-option
                              v-for="item in roomList"
                              :key="item.roomGuid"
                              :label="item.roomName"
                              :value="item.roomGuid"
                            ></el-option>
                          </el-select>
                        </el-form-item>
                      </el-col>
                    </el-row>
                    <el-row>
                      <!-- <el-col :span="11">
                        <el-form-item label="性别" label-width="88px" prop="userSex">
                          <el-radio-group v-model="editformdata.userSex">
                            <el-radio :label="0">男</el-radio>
                            <el-radio :label="1">女</el-radio>
                          </el-radio-group>
                        </el-form-item>
                      </el-col>-->
                      <el-col :span="11">
                        <el-form-item label="手机号" label-width="88px" prop="phoneNumber">
                          <el-input
                            v-model.number="editformdata.phoneNumber"
                            autocomplete="off"
                            style="width: 90%"
                          ></el-input>
                        </el-form-item>
                      </el-col>
                      <el-col :span="11">
                        <el-form-item label="身份证" label-width="88px" prop="idCard">
                          <el-input
                            v-model="editformdata.idCard"
                            autocomplete="off"
                            style="width: 90%"
                          ></el-input>
                        </el-form-item>
                      </el-col>
                      <el-col :span="11">
                        <el-form-item label="家庭住址" label-width="88px" prop="homeAddress">
                          <el-input
                            v-model="editformdata.homeAddress"
                            autocomplete="off"
                            style="width: 90%"
                          ></el-input>
                        </el-form-item>
                      </el-col>
                      <el-col :span="11">
                        <el-form-item label="联系人" label-width="88px" prop="contact">
                          <el-input
                            v-model="editformdata.contact"
                            autocomplete="off"
                            style="width: 90%"
                          ></el-input>
                        </el-form-item>
                      </el-col>
                      <el-col :span="11">
                        <el-form-item label="联系电话" label-width="88px" prop="contactPhone">
                          <el-input
                            v-model="editformdata.contactPhone"
                            autocomplete="off"
                            style="width: 90%"
                          ></el-input>
                        </el-form-item>
                      </el-col>

                      <el-col :span="11">
                        <el-form-item label="电子邮箱" label-width="88px" prop="email">
                          <el-input
                            v-model="editformdata.email"
                            autocomplete="off"
                            style="width: 90%"
                          ></el-input>
                        </el-form-item>
                      </el-col>
                      <!-- <el-col :span="11">
                        <el-form-item label="生日" label-width="88px" prop="birthday">
                          <el-date-picker
                            v-model="editformdata.birthday"
                            type="date"
                            value-format="yyyy-MM-dd"
                            placeholder="选择日期时间"
                            style="width: 90%"
                          ></el-date-picker>
                        </el-form-item>
                      </el-col>-->

                      <el-col :span="11">
                        <el-form-item label="邮政编码" label-width="88px" prop="postCode">
                          <el-input
                            v-model="editformdata.postCode"
                            autocomplete="off"
                            style="width: 90%"
                          ></el-input>
                        </el-form-item>
                      </el-col>
                    </el-row>
                  </el-form>
                </div>
                <div slot="footer" class="dialog-footer">
                  <el-button @click="editvisible">取 消</el-button>
                  <el-button type="primary" @click="eidtconfirmAdd">确 定</el-button>
                </div>
              </el-dialog>
              <!-- 导入窗口 -->
              <el-dialog
                title="用户信息导入"
                :visible.sync="importDialog"
                width="1000px"
                center
                :close-on-click-modal="false"
                :before-close="closeDialogImport"
                class="import"
              >
                <div class="unit_parameter">
                  <div class="grid-content bg-purple aa" v-if="importDialog">
                    <div class="header_select">
                      <div>
                        <el-button type="primary" @click="thetemplate()" size="mini">execl模板下载</el-button>
                      </div>
                      <div class="bulk_import">
                        <el-upload
                          class="upload-demo"
                          action
                          :on-change="handleChange"
                          :on-exceed="handleExceed"
                          :on-remove="handleRemove"
                          :file-list="fileListUpload"
                          :limit="limitUpload"
                          accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel"
                          :auto-upload="false"
                        >
                          <el-button type="primary" @click="handleclickto()" size="mini">浏览文件</el-button>
                        </el-upload>
                      </div>
                      <div class="packge_batch">
                        <el-button
                          type="primary"
                          @click="packgebatchto(tableChecked)"
                          size="mini"
                        >导入数据</el-button>
                      </div>
                    </div>
                    <el-table
                      :data="changestudentlist"
                      :stripe="true"
                      style="width: 100%"
                      border="border"
                      height="40vh"
                      :header-cell-style="headFirst"
                      highlight-current-row
                      @selection-change="handleSelectionChange"
                      :show-overflow-tooltip="true"
                      key="table1"
                      v-loading="importLoad"
                      ref="importTable"
                      :cell-style="(res) => headFirst_col(res, [])"
                    >
                      <!-- <el-table-column label="选择" width="55">
                                    <template slot-scope="scope">
                                        <el-checkbox :checked="scope.row.isKey== 1"/>
                                    </template>
                      </el-table-column>-->
                      <!-- <el-table-column align="center" type="selection" width="55"></el-table-column> -->
                      <el-table-column label="是否选中" prop="isCheck" align="center" width="45">
                        <template slot="header" slot-scope="scope">
                          <el-checkbox
                            :value="isSelectAll"
                            @change="CheckSelectAll"
                            :disabled="isError"
                          />
                        </template>
                        <template slot-scope="scope">
                          <el-checkbox
                            :value="scope.row.isCheck"
                            @change="(isCheck) => CheckSelect(isCheck, scope.row)"
                            :disabled="isError"
                          />
                        </template>
                      </el-table-column>
                      <el-table-column label="错误原因" prop="errorStr" v-if="isError"></el-table-column>
                      <el-table-column label="姓名" prop="userName"></el-table-column>
                      <el-table-column label="编号" prop="userNumber"></el-table-column>
                      <el-table-column label="卡号" prop="cardNumber" v-if="isIdCardMode == '1'"></el-table-column>
                      <el-table-column label="部门" prop="departmentName"></el-table-column>
                      <el-table-column label="分组名称" prop="groupName"></el-table-column>
                      <el-table-column label="入住房间" prop="roomName"></el-table-column>
                      <el-table-column label="性别" prop="userSex"></el-table-column>
                      <el-table-column label="生日" prop="birthday" min-width="140px"></el-table-column>
                      <el-table-column label="身份证" prop="idCard" min-width="160px"></el-table-column>
                      <el-table-column label="手机号" prop="phoneNumber"></el-table-column>
                      <el-table-column label="联系人" prop="contact"></el-table-column>
                      <el-table-column label="联系电话" prop="contactPhone"></el-table-column>
                      <el-table-column label="家庭地址" prop="homeAddress"></el-table-column>
                      <el-table-column label="邮政编码" prop="postCode"></el-table-column>
                      <el-table-column label="邮箱" prop="email"></el-table-column>
                      <el-table-column label="预存款金额（元）" prop="advanceBalance" min-width="110px"></el-table-column>
                    </el-table>
                  </div>
                </div>
                <div class="page">
                  <el-pagination
                    @size-change="handleSizeChangeY"
                    @current-change="handleCurrentChangepageY"
                    :current-page="pageY"
                    :page-sizes="[20, 40, 80, 120]"
                    :page-size="pageSizeY"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="totalY"
                  ></el-pagination>
                </div>
              </el-dialog>
              <div class="page">
                <el-pagination
                  @size-change="handleSizeChange"
                  @current-change="handleCurrentChangepage"
                  :current-page="currentPage"
                  :page-sizes="[10, 20, 30, 40]"
                  :page-size="pageSize"
                  layout="total, sizes, prev, pager, next, jumper"
                  :total="recordCount"
                ></el-pagination>
              </div>
            </div>
          </div>
        </template>
      </dragdrop>
    </div>
  </div>
</template>

<script>
import FileSaver from 'file-saver'
import XLSX from 'xlsx'
import { JSEncrypt } from 'jsencrypt'
import qs from 'qs'
import axios from 'axios'
export default {
  data() {
    //自定义验证密码
    let checkpassword = (rule, value, callback) => {
      if (!value) {
        callback(new Error('请输入密码'))
      } else {
        let passwordReg = /^.*(?=.{3,})(?=.*\d)(?=.*[A-Z])(?=.*[a-z])(?=.*[!@#$%^&*? ]).*$/
        if (!passwordReg.test(value)) {
          callback(
            new Error('最少6位，包括至少1个大写字母，小写字母，数字，特殊字符')
          )
        } else {
          callback()
        }
      }
    }
    let checkEmail = (rule, value, callback) => {
      if (!value) {
        // 通过callback传递错误信息
        callback()
      } else {
        let emailReg = /^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/
        if (!emailReg.test(value)) {
          callback(new Error('请输入正确的邮箱格式！'))
        } else {
          // 没有错误了就直接调用callback
          callback()
        }
      }
    }
    let checkPhone = (rule, value, callback) => {
      if (!value) {
        // 通过callback传递错误信息
        callback()
      } else {
        let emailReg = /^1[3456789]\d{9}$/
        if (!emailReg.test(value)) {
          callback(new Error('请输入正确的手机号码格式！'))
        } else {
          // 没有错误了就直接调用callback
          callback()
        }
      }
    }
    let checkCard = (rule, value, callback) => {
      if (!value) {
        // 通过callback传递错误信息
        callback()
      } else {
        let emailReg = /^[1-8][1-7]\d{4}(?:19|20)\d{2}(?:0[1-9]|1[0-2])(?:0[1-9]|[12]\d|3[01])\d{3}[\dX]$/
        if (!emailReg.test(value)) {
          callback(new Error('请输入正确的身份证格式！'))
        } else {
          // 没有错误了就直接调用callback
          callback()
        }
      }
    }
    return {
      loading: false,
      elform: {},
      cancel: null,
      // 是否为IC发卡模式
      isIdCardMode: '',
      // 是否全选
      isSelectAll: false,
      // 表格中拿出的原始数据
      changestudentY: [],
      // 原始页数
      pageY: 1,
      // 每条个数
      pageSizeY: 20,
      // 总条数
      totalY: 0,
      // 导入的表格
      importLoad: false,
      // 是否显示错误原因
      isError: false,
      //
      filename: '人卡资料',
      changeschoolid: '',
      administrator: '',
      pageSize: 20,
      pageNum: 1,
      currentPage: 1,
      recordCount: 0,
      sortName: '',
      defaultExpandAll: true,
      addDialogFormVisible: false,
      editDialogFormVisible: false,
      importDialog: false,
      custom: false,
      table1: true,
      departmentGuid: '',
      userName: '',
      userNumber: '',
      cardNumber: '',
      limitUpload: 1,
      publicKey:
        'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCx8wyZzYxaffWrJ4jooN554npe5vD2RSQGNXOY5UZz6hcIW0jdEk1KcdclE7mJPiI2DmgUjBp4Lau+bNmZxmLBqFHUMd29mWyqX+LuYVoymxs8f3VJF+7PqZzuKbtSOyXfcyjIIgtB06YlX4SXx4FCErGRx+MDseN2ObHSPme/3wIDAQAB',
      defaultProps: {
        children: 'children',
        label: 'departmentName'
      },
      formThead: {
        userName: { label: '姓名', prop: 'userName', checked: true },
        userNumber: { label: '人员编号', prop: 'userNumber', checked: true },
        cardNumber: { label: '卡号', prop: 'cardNumber', checked: true },
        departmentName: {
          label: '部门',
          prop: 'departmentName',
          checked: true
        },
        groupName: { label: '身份/分组', prop: 'groupName', checked: true },
        roomName: { label: '入住房间', prop: 'roomName', checked: true },
        userSexStr: { label: '性别', prop: 'userSexStr', checked: false },
        birthday: { label: '出生日期', prop: 'birthday', checked: false },
        idCard: { label: '身份证号', prop: 'idCard', checked: false },
        loginName: { label: '登陆名', prop: 'loginName', checked: true },
        phoneNumber: { label: '手机号', prop: 'phoneNumber', checked: true },
        contact: { label: '联系人', prop: 'contact', checked: false },
        contactPhone: {
          label: '联系电话',
          prop: 'contactPhone',
          checked: false
        },
        homeAddress: { label: '家庭地址', prop: 'homeAddress', checked: false },
        postCode: { label: '邮政编码', prop: 'postCode', checked: false },
        email: { label: 'E_mail', prop: 'email', checked: false },
        regTime: { label: '注册时间', prop: 'regTime', checked: false },
        limitPassword: {
          label: '超额密码',
          prop: 'limitPassword',
          checked: false
        },
        platformBalance: {
          label: '平台钱包余额',
          prop: 'platformBalance',
          checked: false
        },
        advanceBalance: {
          label: '预存款金额(元)',
          prop: 'advanceBalance',
          checked: false
        }
        // cardBalance: {
        //   label: '卡内余额(元)',
        //   prop: 'cardBalance',
        //   checked: false
        // }
      },
      changestudentlist: [],
      tableData: [],
      deptTree: [],
      idArr: [null],
      schooloptions: [],
      departmentName: [],
      roomName: [],
      deptForm: [],
      dataTree: [],
      agentlistout: [],
      fileListUpload: [],
      tableChecked: [],
      groupList: [],
      // 楼栋信息
      buildingInfoList: [],
      layersList: [],
      roomList: [],
      addformdata: {
        // 住宿类型
        userType: 0,
        unitGuid: '',
        userGuid: '',
        userName: '',
        userNumber: '',
        cardNumber: '',
        departmentGuid: '',
        departmentName: '',
        userSex: '0',
        birthday: '',
        idCard: '',
        phoneNumber: '',
        contact: '',
        contactPhone: '',
        homeAddress: '',
        email: '',
        loginName: '',
        loginPassword: '',
        postCode: '',
        addformdata: '',
        buildingGuid: '',
        layers: '',
        roomGuid: '',
        roomName: '',
        groupGuid: '',
        limitPassword: '1234',
        operatorGuid: ''
      },
      //
      addformdatamyrules: {
        idCard: [{ validator: checkCard, trigger: 'blur' }],
        departmentGuid: [
          {
            required: true,
            message: '请选择班级',
            trigger: ['blur', 'change']
          }
        ],
        userName: [{ required: true, message: '请输入姓名', trigger: 'blur' }],
        userNumber: [
          { required: true, message: '请输入编号', trigger: 'blur' }
        ],
        email: [{ validator: checkEmail, trigger: 'blur' }],
        phoneNumber: [{ validator: checkPhone, trigger: 'blur' }],
        // loginName: [
        //   { required: true, message: "请输入登录账号", trigger: "blur" },
        // ],
        groupGuid: [
          { required: true, message: '请选择分组', trigger: 'change' }
        ],
        limitPassword: [
          { required: true, message: '长度必须为4位数', trigger: 'blur' },
          { min: 4, max: 4, message: '长度必须为4位数', trigger: 'blur' }
        ]
      },
      editformdata: {
        // 住宿类型
        userType: '',
        unitGuid: '',
        userGuid: '',
        userName: '',
        userNumber: '',
        cardNumber: '',
        departmentGuid: '',
        userSex: '0',
        birthday: '',
        idCard: '',
        phoneNumber: '',
        contact: '',
        contactPhone: '',
        homeAddress: '',
        email: '',
        loginName: '',
        // loginPassword:'',
        postCode: '',
        buildingGuid: '',
        layers: '',
        roomGuid: '',
        roomName: '',
        groupGuid: '',
        limitPassword: ''
      },
      editformdatamyrules: {
        idCard: [{ validator: checkCard, trigger: 'blur' }],
        departmentGuid: [
          {
            required: true,
            message: '请选择班级',
            trigger: ['blur', 'change']
          }
        ],
        userName: [{ required: true, message: '请输入姓名', trigger: 'blur' }],
        userNumber: [
          { required: true, message: '请输入编号', trigger: 'blur' }
        ],
        email: [{ validator: checkEmail, trigger: 'blur' }],
        phoneNumber: [{ validator: checkPhone, trigger: 'blur' }],
        loginName: [
          { required: true, message: '请输入登录账号', trigger: 'blur' }
        ],
        groupGuid: [
          { required: true, message: '请选择分组', trigger: 'change' }
        ],
        limitPassword: [
          { required: true, message: '长度必须为4位数', trigger: 'blur' },
          { min: 4, max: 4, message: '长度必须为4位数', trigger: 'blur' }
        ]
      }
    }
  },
  created() {
    this.changeschoolid = this.$store.state.user.changeschoolid
    this.administrator = sessionStorage.getItem('administrator')
    this.custom = true
  },
  mounted() {
    this.getDeptTree()
    this.getDataTree()
    this.getGroupList()
    this.loadCol()
    // console.log(this.changeschoolid);
  },
  methods: {
    // 楼栋查询
    selectBuilding() {
      // 获取对应区域内的楼栋信息
      this.$http({
        url: this.$http.adornUrl('/api/v1/Student/select-building'),
        method: 'post',
        data: this.$http.adornData({
          messageContent: {
            unitGuid: this.changeschoolid,
            userGuid: this.administrator
          },
          messageType: 0
        })
      }).then(({ data }) => {
        if (data.messageCode == 200) {
          this.buildingInfoList = data.messageContent
        } else {
          this.$message.error(data.errorMessage)
        }
      })
    },
    // 选择楼栋后触发，获取楼层信息
    selectLay(val) {
      this.layersList = []
      this.roomList = []
      this.addformdata.layers = ''
      this.addformdata.roomGuid = ''
      this.editformdata.layers = ''
      this.editformdata.roomGuid = ''
      // alert(this.editformdata.buildingGuid)
      if (val == '') {
        return
      }
      this.buildingInfoList.map(item => {
        if (item.buildingGuid == val) {
          for (let i = 1; i <= item.floors; i++) {
            this.layersList.push({
              label: i,
              value: i
            })
          }
        }
      })
    },
    // 选择楼层后触发，查询房间信息
    selectRoom(val) {
      this.addformdata.roomGuid = ''
      this.editformdata.roomGuid = ''
      this.roomList = []
      if (val == '') {
        return
      }
      this.$http({
        url: this.$http.adornUrl('/api/v1/Student/select-room'),
        method: 'post',
        data: this.$http.adornData({
          messageContent: {
            buildingGuid:
              this.addformdata.buildingGuid || this.editformdata.buildingGuid,
            layers: val,
            unitGuid: this.changeschoolid
          },
          messageType: 0
        })
      }).then(({ data }) => {
        if (data.messageCode == 200) {
          this.roomList = data.messageContent
        } else {
          this.$message.error(data.errorMessage)
        }
      })
    },

    // 重置密码
    resetPassword(row) {
      console.log(row)
      this.$confirm(`是否重置${row.loginName}用户的密码`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.$http({
            url: this.$http.adornUrl('/manager/reset-password'),
            method: 'post',
            data: this.$http.adornData({
              messageContent: {
                operatorGuid: this.administrator,
                userLoginName: row.loginName,
                userGuid: row.userGuid
              },
              messageType: 0
            })
          }).then(({ data }) => {
            if (data.messageCode === 200) {
              this.$message({
                message: '重置成功',
                type: 'success'
              })
            } else {
              this.$message.error(data.errorMessage)
            }
          })
        })
        .catch(() => {})
    },

    //获取分组列表
    getGroupList() {
      this.$http({
        url: this.$http.adornUrl('/unit/unit-user-group-list'),
        method: 'post',
        data: this.$http.adornData({
          messageContent: this.changeschoolid,
          messageType: 0
        })
      }).then(({ data }) => {
        if (data.messageCode == 200) {
          this.groupList = data.messageContent
        }
      })
    },

    //excel模板下载
    thetemplate() {
      let obj = { unitGuid: this.changeschoolid }
      let info = qs.stringify(obj)
      console.log(info)
      this.$http({
        url: this.$http.adornUrl('/department/poi-user-model-download'),
        method: 'post',
        data: qs.stringify(obj),
        headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
        responseType: 'blob'
      }).then(({ data }) => {
        console.log(data)
        this.downloadFile(data)
      })
    },
    downloadFile(data) {
      // 文件导出
      if (!data) {
        return
      }
      const nowtime = this.getimeto()
      let url = window.URL.createObjectURL(new Blob([data]))
      let link = document.createElement('a')
      link.style.display = 'none'
      link.href = url
      link.setAttribute('download', '学生信息批量模板.xlsx')
      document.body.appendChild(link)
      link.click()
    },
    /**
     * 用户导入数据处理
     */
    // 数据初始化
    initList() {
      // 关闭加载
      this.importLoad = false
      // 渲染表格初始化
      this.changestudentlist = []
      // 表格中拿出的原始数据
      this.changestudentY = []
      // 原始页数
      this.pageY = 1
      // 每条个数
      this.pageSizeY = 20
      // 总条数
      this.totalY = 0
      // 原始的显示数据数
      this.showPageSizeY = 20
      this.isSelectAll = false
    },
    // 用户导入分页
    handleSizeChangeY(val) {
      this.pageSizeY = val
      this.getUserList(this.pageY, this.pageSizeY)
    },
    handleCurrentChangepageY(val) {
      this.pageY = val
      this.getUserList(this.pageY, this.pageSizeY)
    },
    // 获取到用户数据，页面渲染
    getUserList(pagenum, pagesize) {
      this.changestudentlist = this.changestudentY.slice(
        (pagenum - 1) * pagesize,
        pagenum * pagesize
      )
    },

    // 选中数据
    CheckSelect(val, row) {
      // 因为是用索引当做id的。
      this.changestudentY[row.id].isCheck = val
      console.log(this.changestudentY)
    },
    // 全选按钮
    CheckSelectAll(val) {
      this.isSelectAll = val
      this.changestudentY.map(item => {
        item.isCheck = val
      })
    },

    // 判别当前学校配置（是否为ID发卡模式）
    getunitconfiguration() {
      this.$http({
        url: this.$http.adornUrl('/manager/unit-config'),
        method: 'post',
        data: this.$http.adornData({
          messageContent: {
            unitGuid: this.changeschoolid,
            userGuid: this.administrator
          },
          messageType: this.messageType
        })
      }).then(({ data }) => {
        if (data.messageCode == 200) {
          //是否ID发卡模式
          this.isIdCardMode = String(data.messageContent.isIdCardMode)
        } else {
          this.$message.error(data.errorMessage)
        }
      })
    },

    // 用户导入显示,
    showImportDialog() {
      // 数据初始化
      this.initList()
      this.getunitconfiguration()
      this.importDialog = true
    },
    // 导入数据处理
    getData() {
      let arr = []
      this.changestudentY.map(item => {
        if (item.isCheck) {
          arr.push(item)
        }
      })
      return arr
    },
    //导入
    packgebatchto() {
      if (this.importLoad) {
        this.$message({
          showClose: true,
          message: '正在批量导入请勿重复操作',
          type: 'warning',
          duration: '500'
        })
        return false
      }
      let tableCheckedto = this.getData()
      if (tableCheckedto[0] && tableCheckedto[0].errorStr) {
        this.$message({
          message: '数据非法',
          type: 'warning'
        })
        return
      }
      let timeOut = Math.ceil(tableCheckedto.length / 1000)
      console.log(timeOut)
      this.$message({
        showClose: true,
        duration: 1000 * (2 + timeOut),
        message: '正在导入，请勿关闭窗口',
        type: 'warning'
      })
      let encryptor = new JSEncrypt()
      encryptor.setPublicKey(this.publicKey)
      for (var i = 0; i < tableCheckedto.length; i++) {
        if (tableCheckedto[i].userSex == '男') {
          tableCheckedto[i].userSex = 0
        }
        if (tableCheckedto[i].userSex == '女') {
          tableCheckedto[i].userSex = 1
        }
        if (tableCheckedto[i].cardNumber) {
          tableCheckedto[i].cardNumber = tableCheckedto[i].cardNumber.toString()

          tableCheckedto[i].loginPassword = encryptor.encrypt(
            this.$md5(tableCheckedto[i].cardNumber)
          )
          tableCheckedto[i].loginName = tableCheckedto[i].cardNumber.toString()
        } else {
          tableCheckedto[i].cardNumber = tableCheckedto[i].cardNumber
        }
        tableCheckedto[i].unitGuid = this.changeschoolid
      }
      if (tableCheckedto.length == 0) {
        this.$message({
          message: '没有批量数据',
          type: 'warning'
        })
        return false
      }
      this.importLoad = true
      // console.log(tableCheckedto);
      this.$httpblob({
        url: this.$httpblob.adornUrl('/department/excel-user-add'),
        method: 'post',
        data: this.$httpblob.adornData({
          messageContent: tableCheckedto,
          messageType: 0
        })
      }).then(({ data }) => {
        // 数据初始化
        this.initList()
        // console.log(data)
        if (data.messageCode == 500) {
          this.$message({
            message: data.errorMessage,
            type: 'warning'
          })
        }
        if (data.messageCode == 200) {
          this.table1 = false
          this.tablelist = data.messageContent
          this.getDeptTree()
          if (data.messageContent.length != 0) {
            this.isError = true
            this.$message({
              showClose: true,
              duration: 1000 * 5,
              message: data.errorMessage,
              type: 'warning'
            })

            let arrto = data.messageContent
            arrto.map((item, index) => {
              item.isCheck = this.isSelectAll
              item.id = index
              item.userSex = item.userSex ? '女' : '男'
            })
            this.changestudentY = arrto
            this.getUserList(this.pageY, this.pageSizeY)
            this.totalY = arrto.length
            this.$nextTick(() => {
              this.$refs['importTable'].doLayout()
            })
          } else {
            this.isError = false
            this.$message({
              showClose: true,
              duration: 1000 * 5,
              message: data.errorMessage,
              type: 'success'
            })
            this.importDialog = false
            this.changestudentlist = []
            this.initpage()
          }
        }
      })
    },
    //导入表格选择变更
    handleSelectionChange(val) {
      this.tableChecked = val
    },
    handleclickto() {},
    //导入函数
    importfxx(obj) {
      // 把错误号去除
      this.isError = false
      // 数据初始化
      this.initList()
      let _this = this
      // 通过DOM取文件数据
      this.file = obj
      var rABS = false //是否将文件读取为二进制字符串
      var f = this.file
      var reader = new FileReader()
      //if (!FileReader.prototype.readAsBinaryString) {
      FileReader.prototype.readAsBinaryString = function(f) {
        var binary = ''
        var rABS = false //是否将文件读取为二进制字符串
        var pt = this
        var wb //读取完成的数据
        var outdata
        var reader = new FileReader()
        reader.onload = function(e) {
          var bytes = new Uint8Array(reader.result)
          var length = bytes.byteLength
          for (var i = 0; i < length; i++) {
            binary += String.fromCharCode(bytes[i])
          }
          var XLSX = require('xlsx')
          if (rABS) {
            wb = XLSX.read(btoa(fixdata(binary)), {
              //手动转化
              type: 'base64'
            })
          } else {
            wb = XLSX.read(binary, {
              type: 'binary'
            })
          }
          outdata = XLSX.utils.sheet_to_json(wb.Sheets[wb.SheetNames[0]]) //outdata就是你想要的东西
          this.da = [...outdata]
          let arr = []
          this.da.map(v => {
            let obj = {}
            obj.userName = v['姓名']
            obj.userNumber = v['编号']
            if (_this.isIdCardMode == '1') {
              obj.cardNumber = v['卡号']
            }
            obj.departmentName = v['部门']
            obj.departmentGuid = v['部门']
            obj.roomName = v['入住房间']
            obj.roomGuid = v['入住房间']
            obj.userSex = v['性别']
            obj.birthday = v['生日']
            obj.idCard = v['身份证']
            obj.phoneNumber = v['手机号']
            obj.contact = v['联系人']
            obj.contactPhone = v['联系人电话']
            obj.homeAddress = v['家庭住址']
            obj.postCode = v['邮政编码']
            obj.email = v['邮箱']
            obj.groupName = v['分组名称']
            obj.advanceBalance = v['预存款金额（元）']

            arr.push(obj)
          })
          _this.studentlist = [...arr]
          let arrto = JSON.parse(JSON.stringify(_this.studentlist))
          // _this.studentlist = arrto
          if (arrto.length > 0) {
            for (var i = 0; i < arrto.length; i++) {
              if (arrto[i].birthday == undefined) {
                arrto[i].birthday = ''
              } else {
                arrto[i].birthday = _this.getdata(arrto[i].birthday)
              }
              arrto[i].unitGuid = this.changeschoolid
            }
          }
          console.log(arrto)

          // _this.changestudentlist = arrto;
          let list = []
          let is = 0
          let indexId = 0;
          arrto.map((item, index) => {
            if (!item.departmentName || !item.userNumber || !item.userName) {
              delete arrto[index]
              is++
            } else {
              item.isCheck = _this.isSelectAll
              item.id = indexId;
              indexId++;
              list.push(item)
            }
          })
          if (is) {
            _this.$message({
              message: `已预览${list.length}条数据，忽略了${is}条未填写必填字段的数据`,
              type: 'warning'
            })
          }
          _this.changestudentY = list
          _this.getUserList(_this.pageY, _this.pageSizeY)
          _this.totalY = list.length
          // console.log(_this.changestudentlist);
          // console.log(_this.changestudentY);
        }
        reader.readAsArrayBuffer(f)
      }

      if (rABS) {
        reader.readAsArrayBuffer(f)
      } else {
        reader.readAsBinaryString(f)
      }
    },
    //导入excel相关
    handleRemove(file, fileList) {
      // 初始化
      this.initList()
      this.isError = false
      this.changestudentlist = []
      this.fileTemp = null
    },
    //导入excel相关
    handleExceed(file, fileList) {
      fileList[0].name = file[0].name
      this.fileTemps = file[0]
      if (this.fileTemps) {
        if (
          this.fileTemps.type ==
            'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' ||
          this.fileTemps.type == 'application/vnd.ms-excel'
        ) {
          this.changestudentlist = []
          this.table1 = true
          this.importfxx(this.fileTemps)
        } else {
          this.$message({
            type: 'warning',
            message: '附件格式错误，请删除后重新上传！'
          })
        }
      } else {
        this.$message({
          type: 'warning',
          message: '请上传附件！'
        })
      }
    },
    //导入excel相关
    handleChange(file, fileList) {
      this.fileTemp = file.raw
      if (this.fileTemp) {
        if (
          this.fileTemp.type ==
            'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' ||
          this.fileTemp.type == 'application/vnd.ms-excel'
        ) {
          this.changestudentlist = []
          this.table1 = true
          this.importfxx(this.fileTemp)
        } else {
          this.$message({
            type: 'warning',
            message: '附件格式错误，请删除后重新上传！'
          })
        }
      } else {
        this.$message({
          type: 'warning',
          message: '请上传附件！'
        })
      }
    },
    //时间转换
    getdata(date) {
      // let date = 44120
      // let date = 44043.26566  44045.59899

      date = Math.round(date * 100000) / 100000
      // console.log(date)
      // console.log((date - 1) * 24 * 3600000)
      // date = new Date((date - 1) * 24 * 3600000 + 1)
      var Minustime = 1.33333 * 24 * 3600000
      date = new Date(date * 24 * 3600000 - Minustime)
      date.setYear(date.getFullYear() - 70)
      // console.log(date)
      return this.dateFormat('YYYY-mm-dd', date)
      // console.log(this.dateFormat("YYYY-mm-dd HH:MM:SS",date))
    },
    dateFormat(fmt, date) {
      let ret
      const opt = {
        'Y+': date.getFullYear().toString(), // 年
        'm+': (date.getMonth() + 1).toString(), // 月
        'd+': date.getDate().toString(), // 日
        'H+': date.getHours().toString(), // 时
        'M+': date.getMinutes().toString(), // 分
        'S+': date.getSeconds().toString() // 秒
        // 有其他格式化字符需求可以继续添加，必须转化成字符串
      }
      // console.log(opt)
      for (let k in opt) {
        ret = new RegExp('(' + k + ')').exec(fmt)
        if (ret) {
          fmt = fmt.replace(
            ret[1],
            ret[1].length == 1 ? opt[k] : opt[k].padStart(ret[1].length, '0')
          )
        }
      }
      return fmt
    },
    //多选框修改事件
    checkboxChanged() {
      //保存用户自定义列
      localStorage.setItem('customUser', JSON.stringify(this.formThead))
      this.$nextTick(() => {
        this.$refs['tableData'].doLayout()
      })

      // console.log(localStorage.getItem('customUser'));
    },
    //初次加载列
    loadCol() {
      if (localStorage.getItem('customUser')) {
        let tempThead = JSON.parse(JSON.stringify(this.formThead))
        //自定义用户列已经编辑过
        // console.log(localStorage.getItem('customUser'));
        let arr = Object.keys(this.formThead)
        let arr1 = Object.keys(JSON.parse(localStorage.getItem('customUser')))
        if (JSON.stringify(arr) == JSON.stringify(arr1)) {
          this.formThead = JSON.parse(localStorage.getItem('customUser'))
        } else {
          console.log('失败')
          this.formThead = tempThead
        }
      }
    },
    //用户信息导出
    async exportexeclto(type) {
      if (this.tableData.length == 0) {
        this.$message({
          message: '请查询数据后在进行操作',
          type: 'warning'
        })
        return false
      }
      this.agentlistout = await this.outexecel()
      if (type == 'print') {
        this.printJS()
      } else {
        this.export2Excel()
      }
    },
    // 打印
    printJS() {
      let someJSONdata = this.agentlistout
      const title = '人员信息'
      this.unitName = sessionStorage.getItem('unitName')
      const properties = []
      // 拿到数据,filterValArr为数据值，为数据标题，一一对应
      const { filterValArr, tHeader } = this.getIsPrint()
      filterValArr.map((item, index) => {
        properties.push({
          displayName: tHeader[index],
          field: filterValArr[index]
        })
        // if (tHeader[index] == 'birthday' || tHeader[index] == 'regTime') {
        //   properties.push({
        //     displayName: tHeader[index],
        //     field: filterValArr[index],
        //     columnSize: 200 / (Object.keys(this.formThead).length + 2) + '%'
        //   })
        // } else {
        //   properties.push({
        //     displayName: tHeader[index],
        //     field: filterValArr[index],
        //     columnSize: 100 / (Object.keys(this.formThead).length + 2) + '%'
        //   })
        // }
      })
      // 打印
      this.$printJS({
        // 眉头
        documentTitle: `${this.unitName}`,
        /**
         * 获取表头的信息
         * @param {*} title 表名
         * @param {*} unitName 单位
         * @param {*} time 时间
         */
        header: this.printHeader(
          title,
          this.unitName,
          this.getNowTime('yy-mm-dd')
        ),
        printable: someJSONdata,
        properties: properties,
        type: 'json',
        // 是否每页都显示头部
        // repeatTableHeader:false,
        headerRow: 1
        // style: style,
      })
    },

    // 查询到所有人员的数据
    outexecel() {
      let _this = this
      return new Promise(function(resolve, reject) {
        _this
          .$http({
            url: _this.$http.adornUrl('/api/v1/Student/user-user-info-page'),
            method: 'post',
            data: _this.$http.adornData({
              messageContent: {
                asc: true,
                pageNum: 1,
                pageSize: _this.recordCount,
                searchInfo: {
                  departmentGuid: _this.departmentGuid,
                  unitGuid: _this.changeschoolid,
                  cardNumber: _this.cardNumber,
                  userName: _this.userName,
                  userNumber: _this.userNumber
                },
                sortName: _this.sortName
              },
              messageType: 0
            })
          })
          .then(({ data }) => {
            if (data.messageCode == 200) {
              let listArr = data.messageContent.data
              for (var i = 0; i < listArr.length; i++) {
                if (listArr[i].userSex != null) {
                  if (listArr[i].userSex == '0') {
                    listArr[i].userSex = '男'
                  }
                  if (listArr[i].userSex == '1') {
                    listArr[i].userSex = '女'
                  }
                  listArr[i].platformBalance = _this.amountyua(
                    listArr[i].platformBalance
                  )
                  listArr[i].advanceBalance = _this.amountyua(
                    listArr[i].advanceBalance
                  )
                  listArr[i].cardBalance = _this.amountyua(
                    listArr[i].cardBalance
                  )
                }
              }
              resolve(listArr)
            } else {
              reject(data.errorMessage)
              this.$message.error(data.errorMessage)
            }
          })
      })
    },
    // 拿到表头数据
    getIsPrint() {
      let valArr = []
      let tHeader = []
      for (let key in this.formThead) {
        if (this.formThead[key].checked) {
          if (key == 'userSexStr') {
            valArr.push('userSex')
          } else {
            valArr.push(this.formThead[key].prop)
          }
          tHeader.push(this.formThead[key].label)
        }
      }

      return { filterValArr: valArr, tHeader }
      // console.log(this.formThead)
    },
    formatJson(filterVal, jsonData) {
      return jsonData.map(v => filterVal.map(j => v[j]))
    },
    export2Excel() {
      const nowtime = this.getimeto()
      require.ensure([], () => {
        let multiHeader = []
        let merges = []
        const { filterValArr, tHeader } = this.getIsPrint()

        const { export_json_to_excel } = require('../../excel/Export2Excel')
        const filterVal = filterValArr
        const list = this.agentlistout
        const data = this.formatJson(filterVal, list)
        export_json_to_excel({
          multiHeader,
          header: tHeader,
          data,
          merges,
          filename: this.filename + this.getimeto(),
          tableheader: '1'
        })
      })
    },
    //导入窗口关闭
    closeDialogImport() {
      this.changestudentlist = []
      this.isError = false
      this.importDialog = false
    },
    //新增用户窗口关闭
    closeDialogAdd() {
      this.$refs['addformdata'].resetFields()
      this.addDialogFormVisible = false
    },
    //取消新增用户
    addvisible() {
      this.$refs['addformdata'].resetFields()
      this.addDialogFormVisible = false
    },
    //编辑用户窗口关闭
    closeDialogEdit() {
      // if (this.cascaderEditChanged){
      //     this.editformdata.roomGuid = "";
      //     this.cascaderEditChanged = false
      // }
      this.$refs['editformdata'].resetFields()
      this.editDialogFormVisible = false
    },
    //取消编辑用户
    editvisible() {
      // if (this.cascaderEditChanged){
      //     this.roomValue = [];
      //     this.cascaderEditChanged = false
      // }
      this.$refs['editformdata'].resetFields()
      this.editDialogFormVisible = false
    },
    //
    handleChangeDept(value) {
      // console.log(value);
      // console.log(this.addformdata.roomValue);
      let node = []
      if (this.addDialogFormVisible) {
        node = this.$refs.cascaderAddDept.getCheckedNodes()
        // console.log(node);
        this.addformdata.departmentGuid = node[0].value
        this.addformdata.departmentName = node[0].label
        // console.log(this.addformdata.departmentName,this.addformdata.departmentGuid);
      } else if (this.editDialogFormVisible) {
        node = this.$refs.cascaderEditDept.getCheckedNodes()
        this.editformdata.departmentGuid = node[0].value
        this.editformdata.departmentName = node[0].label
      }
      console.log(node)
    },
    //房间选择
    handleChangeRoom(value) {
      // console.log(value);
      // console.log(this.addformdata.roomValue);
      let node = []
      if (this.addDialogFormVisible) {
        node = this.$refs.cascaderAddRoom.getCheckedNodes()
        // console.log(node);
        this.addformdata.roomGuid = node[0].value
        this.addformdata.roomName = node[0].label
        // console.log(this.addformdata.roomName,this.addformdata.roomGuid);
      } else if (this.editDialogFormVisible) {
        node = this.$refs.cascaderEditRoom.getCheckedNodes()
        this.editformdata.roomGuid = node[0].value
        this.editformdata.roomName = node[0].label
        // this.cascaderEditChanged = true
      }
      console.log(node[0].value)
    },
    //递归增加各节点name，并且删除type为'room'的children
    recursiveRoom(dataTree) {
      for (var i in dataTree) {
        dataTree[i].value = dataTree[i].name
        if (dataTree[i].type == 'room') {
          delete dataTree[i].children
        }
        if (dataTree[i].children) {
          this.recursiveRoom(dataTree[i].children)
        }
      }
    },
    //获取区域楼栋房间树信息
    getDataTree() {
      this.$http({
        url: this.$http.adornUrl('/area/room/get-area-room-tree'),
        method: 'post',
        data: this.$http.adornData({
          messageContent: {
            unitGuid: this.changeschoolid,
            userGuid: this.administrator
          },
          messageType: 0
        })
      }).then(({ data }) => {
        if (data.messageCode === 200) {
          this.dataTree = data.messageContent
          this.recursiveRoom(this.dataTree)
          // console.log(JSON.stringify(this.dataTree));
        }
      })
    },
    // 条件查询用户信息
    gotosearch() {
      this.pageNum = 1
      this.initpage()
    },
    //重置查询条件
    resetfilter() {
      this.userName = ''
      this.userNumber = ''
      this.cardNumber = ''
    },
    /**
     * 新增编辑
     */
    // 新增用户
    handleAddclick() {
      this.buildingInfoList = []
      this.layersList = []
      this.roomList = []
      this.addformdata.buildingGuid = ''
      this.addformdata.layers = ''
      this.addformdata.roomGuid = ''
      // 获取班级列表
      this.getDeptTree()
      // 获取房间列表
      // this.getDataTree()
      // 获取分组信息
      this.getGroupList()
      // 获得楼栋信息
      this.selectBuilding()
      this.addDialogFormVisible = true
    },
    // 编辑用户
    addOrUpdateHandle(row) {
      this.addformdata.buildingGuid = ''
      this.addformdata.layers = ''
      this.addformdata.roomGuid = ''
      // 获取班级列表
      this.getDeptList()
      // 获取房间列表
      this.getDataTree()
      // 获得楼栋信息
      this.selectBuilding()
      this.editformdata.unitGuid = this.changeschoolid
      this.editformdata.userGuid = row.userGuid
      this.editformdata.userName = row.userName
      this.editformdata.userNumber = row.userNumber
      this.editformdata.cardNumber = row.cardNumber
      this.editformdata.departmentGuid = row.departmentGuid
      this.editformdata.userSex = row.userSex
      this.editformdata.birthday = row.birthday
      this.editformdata.idCard = row.idCard
      this.editformdata.phoneNumber = row.phoneNumber
      this.editformdata.contact = row.contact
      this.editformdata.contactPhone = row.contactPhone
      this.editformdata.homeAddress = row.homeAddress
      this.editformdata.email = row.email
      this.editformdata.loginName = row.loginName
      this.editformdata.loginPassword = row.loginPassword
      this.editformdata.postCode = row.postCode
      this.editformdata.buildingGuid = row.buildingGuid
      this.editformdata.layers = row.layers || ''
      this.editformdata.roomGuid = row.roomGuid
      this.editformdata.roomName = row.roomName
      this.editformdata.limitPassword = row.limitPassword
      this.editformdata.groupGuid = row.groupGuid
      this.editformdata.userType = row.userType
      // 获取对应区域内的楼栋信息
      this.$http({
        url: this.$http.adornUrl('/api/v1/Student/select-building'),
        method: 'post',
        data: this.$http.adornData({
          messageContent: {
            unitGuid: this.changeschoolid,
            userGuid: this.administrator
          },
          messageType: 0
        })
      }).then(({ data }) => {
        if (data.messageCode == 200) {
          this.buildingInfoList = data.messageContent
          this.layersList = []
          this.buildingInfoList.map(item => {
            if (item.buildingGuid == row.buildingGuid) {
              for (let i = 1; i <= item.floors; i++) {
                this.layersList.push({
                  label: i,
                  value: i
                })
              }
            }
          })
          this.$http({
            url: this.$http.adornUrl('/api/v1/Student/select-room'),
            method: 'post',
            data: this.$http.adornData({
              messageContent: {
                buildingGuid: row.buildingGuid,
                layers: row.layers,
                unitGuid: this.changeschoolid
              },
              messageType: 0
            })
          }).then(({ data }) => {
            if (data.messageCode == 200) {
              this.roomList = data.messageContent
            } else {
              this.$message.error(data.errorMessage)
            }
          })
        } else {
          this.$message.error(data.errorMessage)
        }
      })
      // console.log(this.editformdata.roomGuid);
      // this.getRoomParentValue(this.dataTree);
      this.editDialogFormVisible = true
    },
    // 跳转到学生H5详情
    toH5User(row) {
      this.$confirm('即将跳转到学生H5详情，是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.H5UserUrl(row.userGuid)
        })
        .catch(() => {})
    },
    // 跳转到学生H5详情请求
    H5UserUrl(userGuid) {
      this.$http({
        url: this.$http.adornUrl('/api/v1/login-auth-unit'),
        method: 'post',
        data: this.$http.adornData({
          messageContent: {
            userGuid: userGuid,
            unitGuid: this.changeschoolid
          },
          messageType: 0
        })
      }).then(({ data }) => {
        if (data.messageCode === 200) {
          console.log(window.SITE_CONFIG.h5Url)
          console.log(`?login-auth=${data.messageContent}`)
          if (process.env.NODE_ENV == 'development') {
            window.open(
              `http://127.0.0.1:5500/login.html?login-auth=${data.messageContent}`
            )
          } else {
            window.open(
              `${window.SITE_CONFIG.h5Url}?login-auth=${data.messageContent}`
            )
          }
        } else {
          this.$message.error(data.errorMessage)
          return
        }
      })
    },
    // 删除用户
    removeUser(row) {
      this.$confirm('是否删除该用户信息?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.deleteUser(row.userGuid)
        })
        .catch(() => {})
    },
    // 删除用户请求
    deleteUser(userGuid) {
      this.$http({
        url: this.$http.adornUrl('/api/v1/Student/info-student-delete'),
        method: 'post',
        data: this.$http.adornData({
          messageContent: {
            agentGuid: this.userGuid,
            userGuid: userGuid,
            unitGuid: this.changeschoolid
          },
          messageType: 0
        })
      }).then(({ data }) => {
        if (data.messageCode === 200) {
          this.$message({
            message: '删除成功',
            type: 'success'
          })
          this.initpage()
        } else {
          this.$message.error(data.errorMessage)
          return
        }
      })
    },
    // 部门树节点点击
    handleNodeClick(data) {
      this.departmentGuid = data.departmentGuid
      this.departmentName = data.departmentName
      this.pageNum = 1
      this.initpage()
    },
    // 获取部门列表
    getDeptList() {
      this.$http({
        url: this.$http.adornUrl('/department/query-department-info'),
        method: 'post',
        data: this.$http.adornData({
          messageContent: {
            agentGuid: this.administrator,
            unitGuid: this.changeschoolid
          },
          messageType: 0
        })
      }).then(({ data }) => {
        if (data.messageCode == 200) {
          this.deptForm = data.messageContent
        } else {
          this.$message.error(data.errorMessage)
        }
      })
    },
    // 新增确认
    confirmAdd() {
      this.$refs['addformdata'].validate(valid => {
        if (valid) {
          let encryptor = new JSEncrypt()
          encryptor.setPublicKey(this.publicKey)
          this.addformdata.unitGuid = this.changeschoolid
          // 把编号当做用户名
          this.addformdata.loginName = this.addformdata.userNumber

          this.addformdata.loginPassword = encryptor.encrypt(
            this.$md5(this.addformdata.loginName)
          )
          this.addformdata.operatorGuid = this.administrator
          // if (this.addformdata.roomGuid.length == 0) {
          //   this.addformdata.roomGuid = ''
          // }
          if (this.addformdata.userType == 2) {
            delete this.addformdata.buildingGuid
            delete this.addformdata.layers
            delete this.addformdata.roomGuid
          }
          // console.log(this.addformdata);
          this.$http({
            url: this.$http.adornUrl('/api/v1/Student/info-student-add'),
            method: 'post',
            data: this.$http.adornData({
              messageContent: this.addformdata,
              messageType: this.messageType
            })
          }).then(({ data }) => {
            // console.log(this.addformdata);
            if (data.messageCode === 500) {
              this.$message.error(data.errorMessage)
            }
            if (data.messageCode === 200) {
              this.$message({
                message: '添加用户成功',
                type: 'success'
              })
              this.initAddForm()
              this.initpage()
              this.addDialogFormVisible = false
            } else {
              this.$message.error(data.errorMessage)
            }
          })
        }
      })
    },
    // 编辑确认
    eidtconfirmAdd() {
      this.$refs['editformdata'].validate(valid => {
        if (this.editformdata.userType == 2) {
          delete this.editformdata.buildingGuid
          delete this.editformdata.layers
          delete this.editformdata.roomGuid
        }
        if (valid) {
          this.editformdata.unitGuid = this.changeschoolid
          this.$http({
            url: this.$http.adornUrl('/api/v1/Student/info-student-update'),
            method: 'post',
            data: this.$http.adornData({
              messageContent: this.editformdata,
              messageType: this.messageType
            })
          }).then(({ data }) => {
            // console.log(data);
            if (data.messageCode === 500) {
              this.$message.error(data.errorMessage)
            }
            if (data.messageCode === 200) {
              this.$message({
                message: '编辑用户信息成功',
                type: 'success'
              })
              this.initEditForm()
              this.initpage()
              this.editDialogFormVisible = false
            } else {
              this.$message.error(data.errorMessage)
            }
          })
        }
      })
    },
    // 初始化新增表单
    initAddForm() {
      this.$nextTick(() => {
        this.$refs['addformdata'].resetFields()
      })
    },
    // 初始化修改表单
    initEditForm() {
      this.$nextTick(() => {
        this.$refs['editformdata'].resetFields()
      })
    },
    // 部门树
    getDeptTree() {
      this.$http({
        url: this.$http.adornUrl('/department/select-department-tree'),
        method: 'post',
        data: this.$http.adornData({
          messageContent: this.changeschoolid,
          messageType: 0
        })
      }).then(({ data }) => {
        // console.log(data.messageContent);
        if (data.messageCode == 200) {
          this.deptTree = data.messageContent
          console.log(this.deptTree)
          this.recursiveget(this.deptTree)
          // this.idArr = []
          // this.getId(this.deptTree)
          console.log(this.deptTree)
          // console.log(JSON.stringify(this.deptTree));
        } else {
          this.$message.error(data.errorMessage)
        }
      })
    },
    //递归添加
    recursiveget(deptTree) {
      for (var i in deptTree) {
        deptTree[i].value = deptTree[i].departmentGuid
        deptTree[i].label = deptTree[i].departmentName
        if (deptTree[i].children.length == 0) {
          delete deptTree[i].children
        } else {
          this.recursiveget(deptTree[i].children)
        }
      }
    },
    //获取递归id
    getId(deptTree) {
      deptTree.forEach(ele => {
        if (ele.flag == true) {
          this.idArr.push(ele.id)
          if (ele.children && ele.children.length > 0) {
            this.getId(ele.children)
          }
        }
      })
    },
    handleSizeChange(val) {
      this.pageSize = val
      this.initpage()
    },
    handleCurrentChangepage(val) {
      this.pageNum = val
      this.initpage()
    },
    // 初始化人事资料页面
    initpage() {
      this.loading = true
      // 终止上一次请求
      this.cancelGetMsg()
      // 取消请求函数
      let CancelToken = axios.CancelToken
      this.$http({
        url: this.$http.adornUrl('/api/v1/Student/user-user-info-page'),
        method: 'post',
        data: this.$http.adornData({
          messageContent: {
            asc: true,
            pageNum: this.pageNum,
            pageSize: this.pageSize,
            searchInfo: {
              departmentGuid: this.departmentGuid,
              unitGuid: this.changeschoolid,
              cardNumber: this.cardNumber,
              userName: this.userName,
              userNumber: this.userNumber
            },
            sortName: this.sortName
          },
          messageType: 0
        }),

        // 取消请求对象// 这个参数 c 就是CancelToken构造函数里面自带的取消请求的函数，这里把该函数当参数用 })
        cancelToken: new CancelToken(c => {
          this.cancel = c
        })
      }).then(({ data }) => {
        this.loading = false
        if (data.messageCode == 200) {
          this.tableData = data.messageContent.data || []
          this.recordCount = data.messageContent.recordCount
          this.currentPage = data.messageContent.pageNum
          if (this.tableData.length == 0) {
            this.$message({
              message: '查询成功当前暂无数据',
              type: 'success'
            })
          }
          this.tableData.forEach(item => {
            if (item.userSex === 0) {
              this.$set(item, 'userSexStr', '男')
            } else {
              this.$set(item, 'userSexStr', '女')
            }
          })
          // console.log(this.tableData);
        } else {
          this.$message.error(data.errorMessage)
        }
      })
    },
    // 终止请求
    cancelGetMsg() {
      if (typeof this.cancel === 'function') {
        this.cancel()
      }
    }
  },
  filters: {
    filtersex: function(sex) {
      if (sex == '0') {
        return '男'
      } else if (sex == '1') {
        return '女'
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.user-info {
  // .unit_parameter {
  //   height: 50vh;
  //   overflow-y: auto;
  // }
  /deep/.el-form-item--mini.el-form-item,
  .el-form-item--small.el-form-item {
    margin-bottom: 5px;
  }
  /deep/.el-dialog--center .el-dialog__body {
    padding-top: 0;
    padding-left: 100px;
  }
  .import {
    /deep/.el-dialog--center .el-dialog__body {
      padding-left: 25px;
    }
  }
  //滚动条的宽度
  ::-webkit-scrollbar {
    width: 10px;
    height: 10px;
  }
  //滚动条的滑块
  ::-webkit-scrollbar-thumb {
    background-color: #a1a3a9;
    border-radius: 3px;
  }
  // height: 86vh;
  .all_main {
    .form {
      padding-top: 10px;
    }
    height: 100%;
    .header_title {
      white-space:nowrap;
      padding: 20px 0;
      font-weight: bolder;
      text-align: left;
      border-bottom: 1px solid #e5e9f2;
      color: #909399;
    }
    .all_left {
      height: 100%;
      .bg-purple {
        height: 100%;
        // overflow-x: scroll;
        // white-space: nowrap;
        // padding: 0 10px;
        .header_title {
          padding: 20px 0;
          font-weight: bolder;
          text-align: center;
          border-bottom: 1px solid #e5e9f2;
          color: #909399;
          overflow: hidden;
        }
        .department_tree {
          // width: 250px;
          height: calc(100vh - 200px);
          overflow-y: auto;
          &::-webkit-scrollbar {
            width: 0;
            height: 0;
            background-color: transparent;
          }
          // padding-top: 20px;
          font-weight: bolder;
          .custom-tree-node {
            padding-left: 10px;
            font-size: 15px;
            .colorfont {
              color: DeepSkyBlue;
            }
          }
        }
      }
    }
    .all_right {
      .el-table__body-wrapper .is-scrolling-left {
        height: 500px;
      }
      height: calc(100vh - 135px);
      overflow-y: auto;
      &::-webkit-scrollbar {
        width: 0;
        height: 0;
        background-color: transparent;
      }
      .bg-purple {
        height: 100%;
        .header_title {
          padding: 10px 0 20px 0;
          font-weight: bolder;
          text-align: center;
          border-bottom: 1px solid #e5e9f2;
          color: #909399;
        }
        .el-table th {
          height: 100%;
          display: table-cell !important;
        }
        .page {
          padding-bottom: 10px;
          display: flex;
          justify-content: center;
          align-items: center;
        }
        .header_select {
          height: 35px;
          // background-color: #F5F5F5;
          width: 98%;

          display: flex;
          align-items: center;
          .cardnumber,
          .username,
          .usernumber {
            display: flex;
            align-items: center;
            padding-left: 10px;
            width: 200px;
            div:nth-child(1) {
              width: 40px;
            }
          }
          .searchbutton {
            // height:36px;
            padding-left: 10px;
            display: flex;
            flex: 1;
            justify-content: space-between;
            .addstudent {
              padding-right: 20px;
            }
            .el-checkbox {
              // align-self: left;
              width: 150px;
              margin-top: 20px;
            }
          }
          .bulk_import {
            padding-left: 20px;
            .upload-demo {
              display: flex;
              align-items: center;
              /deep/.el-upload-list__item-name {
                margin-right: 22px;
              }
            }
          }
          .packge_batch {
            padding-left: 20px;
          }
        }
      }
    }
  }
}
.grid-content.bg-purple.aa {
  // margin-left: -85px !important;
}
</style>